//import java.awt.image.AreaAveragingScaleFilter;
import java.util.ArrayList;
import java.util.Random;


public class Talia {
    final int ILOSCKART = 52;
    ArrayList<Karta> karty;

    public Talia()
    {
        karty = new ArrayList<>(ILOSCKART);
        generujTalie();

    }

    public void dodajKarty(ArrayList<Karta> kartyDoDodania)
    {
        if(karty.size()+kartyDoDodania.size()<= 52)
            karty.addAll(kartyDoDodania);
    }

    private void generujTalie()
    {
        Kolor[] kolory = Kolor.values();
        Figura[] figury = Figura.values();


        for(Kolor kolor : kolory)
        {
            for(Figura figura : figury)
            {
                karty.add(new Karta(figura,kolor));
            }
        }

    }

    public int iloscKart()
    {
        return karty.size();
    }

    public Karta losujKarte()
    {
        Random rnd = new Random();
        return karty.remove(rnd.nextInt(iloscKart()));
    }

    public Reka losujReke()
    {
        ArrayList<Karta> reka = new ArrayList<>(4);

        reka.add(losujKarte());
        reka.add(losujKarte());
        reka.add(losujKarte());
        reka.add(losujKarte());

        return new Reka(reka);
    }

    public String toString()
    {
        StringBuilder sb = new StringBuilder();
        int licznik = 1;
        for(Karta k : karty)
        {
            sb.append(k).append(" | ");
            if(licznik++ % 10 == 0)
                sb.append("\n");
        }
        return sb.toString();
    }

}
